home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / 2020HalfGateway / 2020RecipientReport.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  4.0 KB  |  169 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        2020RecipientReport.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14.  
  15. #ifndef __BLJSTANDARDINCLUDES__
  16. #include "BLJStandardIncludes.h"
  17. #endif
  18.  
  19. #ifndef __2020RECIPIENTREPORT__
  20. #include "2020RecipientReport.h"
  21. #endif
  22.  
  23. #ifndef __AYSTHREADGLUE__
  24. #include "AYSThreadGlue.h"
  25. #endif
  26.  
  27. #ifndef __MAILBUFFER__
  28. #include "MailBuffer.h"
  29. #endif
  30.  
  31. #ifndef __DEBUGGINGGEAR__
  32. #include "DebuggingGear.h"
  33. #endif
  34.  
  35. #ifndef __BLJOCEUTILITIES__
  36. #include "BLJOCEUtilities.h"
  37. #endif
  38.  
  39. #ifndef __UTILITIES__
  40. #include "Utilities.h"
  41. #endif
  42.  
  43.  
  44. T2020RecipientReport::T2020RecipientReport(long queueID, long sequenceNumber) {
  45.  
  46.     //    Open up the recipient report, extract all of it's information into our own fields,
  47.     //    and then close the recipient report.
  48.  
  49.     fQueueID = queueID;
  50.     fSequenceNumber = sequenceNumber;
  51.  
  52.     fRecipientReportCount = 0;
  53.     fRecipientReport = nil;
  54.  
  55.     TRY
  56.     {
  57.         MSAMOpenPB openPB;
  58.         memset(&openPB, 0, sizeof(openPB));
  59.  
  60.         openPB.queueRef = queueID;
  61.         openPB.seqNum = sequenceNumber;
  62.  
  63.         FAILOSErr(MSAMOpenSleep((MSAMParam*) &openPB));
  64.  
  65.         MSAMGetBlockPB getBlockPB;
  66.         
  67.         TRY
  68.         {
  69.             getBlockPB.mailMsgRef = openPB.mailMsgRef;
  70.             getBlockPB.blockType.msgCreator = kIPMSignature;
  71.             getBlockPB.blockType.msgType = kMailReportType;
  72.             getBlockPB.blockIndex = 1;
  73.             getBlockPB.buffer = AllocateMailBuffer(0, 0);
  74.             getBlockPB.dataOffset = 0;
  75.             FAILOSErr(MSAMGetBlockSleep((MSAMParam*) &getBlockPB));
  76.             DisposeMailBuffer ( getBlockPB.buffer );
  77.  
  78.             //    Allocate a handle into which we'll read the contents of this block.
  79.             fRecipientReport = FAILNewHandle(getBlockPB.remaining);
  80.  
  81.             //    Now, lock our data handle and read the complete contents of the report block into
  82.             //    this data handle.
  83.             HLock(fRecipientReport);
  84.  
  85.             getBlockPB.buffer = AllocateMailBuffer(GetHandleSize(fRecipientReport), *fRecipientReport);
  86.             getBlockPB.dataOffset = 0;
  87.             FAILOSErr(MSAMGetBlockSleep((MSAMParam*) &getBlockPB));
  88.  
  89.             HUnlock(fRecipientReport);
  90.  
  91.             //    Lastly, calculate how many recipient reports are in this report
  92.             fRecipientReportCount = (GetHandleSize(fRecipientReport) - sizeof(IPMReportBlockHeader)) / sizeof(OCERecipientReport);
  93.  
  94. #if debug
  95.             keith << "T2020RecipientReport, report contains " << fRecipientReportCount << " recipient reports." << endl;
  96. #endif
  97.             keith << *this;
  98.         }
  99.         EXCEPTION
  100.         {
  101.         }
  102.         ENDEXCEPTION;
  103.  
  104.         DisposeMailBuffer ( getBlockPB.buffer );
  105.         
  106.         MSAMClosePB    closePB;
  107.  
  108.         closePB.mailMsgRef = openPB.mailMsgRef;
  109.         FAILOSErr(MSAMCloseSleep((MSAMParam*) &closePB));
  110.     }
  111.     EXCEPTION
  112.     {
  113.         DeallocateHandle(fRecipientReport);
  114.         fRecipientReport = nil;
  115.     }
  116.     ENDEXCEPTION
  117.  
  118. }
  119.  
  120. T2020RecipientReport::~T2020RecipientReport() {
  121.  
  122.     DisposeIfHandle (fRecipientReport);
  123.  
  124. }
  125.  
  126. short T2020RecipientReport::GetRecipientCount() const
  127. {
  128.     return fRecipientReportCount;
  129. }
  130.  
  131. Boolean T2020RecipientReport::GetRecipientStatus(short index, short& recipientIndex, OSErr& recipientStatus) const
  132. {
  133.     unused(index);
  134.  
  135.     if ((index >= 1) && (index <= fRecipientReportCount)) {
  136.         OCERecipientReport*    report = (OCERecipientReport *) (*fRecipientReport + sizeof(OCERecipientReport));
  137.  
  138.         recipientIndex = report[index].rcptIndex;
  139.         recipientStatus = report[index].result;
  140.         return true;
  141.     }
  142.  
  143.     recipientIndex = 0;
  144.     recipientStatus = noErr;
  145.     return false;
  146. }
  147.  
  148. ostream& T2020RecipientReport::operator >> ( ostream& outStream ) const
  149. {
  150.     IPMReportBlockHeader*    headerP = (IPMReportBlockHeader*) (*fRecipientReport);
  151.  
  152.     outStream << "T2020RecipientReport: msgID=" << headerP ->msgID << " creationTime=" << headerP->creationTime << endl;
  153.     outStream << " Contains " << GetRecipientCount() << " recipients." << endl;
  154.     for (short index = 1; index <= GetRecipientCount(); ++index) {
  155.         short    recipientIndex;
  156.         OSErr    status;
  157.  
  158.         outStream << " " << index << ". ";
  159.         if (GetRecipientStatus(index, recipientIndex, status)) {
  160.             outStream << " recIndex=" << recipientIndex << " status=" << status;
  161.         } else {
  162.             outStream << " not present";
  163.         }
  164.         outStream << flush << endl;
  165.     }
  166.     
  167.     return outStream;
  168. }
  169.